<% title_tag t("users.register_user") %>
<%
auth_session = session[:omniauth] || {}
auth_info = auth_session["info"] || {}
if auth_info
  resource.omniauth_provider = auth_session["provider"]
  resource.omniauth_uid = auth_session["uid"]

  resource.email = auth_info["email"] if resource.email.blank?
  resource.name = auth_info["name"] if resource.name.blank?
  if resource.login.blank?
    resource.login = auth_info["login"] || auth_info["name"]
  end
end
%>
<div class="flex justify-center">
  <div class="w-full sm:w-2/3 md:w-1/2">
    <div class="card card-lg">
      <div class="card-body">
        <div class="card-title">
          <%= t("users.register_user") %>
          <div class="actions hide-ios">
            <%= link_to t("common.login"), new_session_path(resource_name) %>
          </div>
        </div>
        <% if auth_info.present? %>
          <div class="alert">
            <h4 class="alert-heading"><%= t("users.complete_your_info") %></h4>
            <p><%= t("users.binding_via_html", provider: Homeland::Utils.omniauth_name(resource.omniauth_provider)) %></p>
            <p><%= t("users.binding_has_account_html") %></p>
          </div>
        <% end %>
        <%= form_for resource, as: resource_name, url: registration_path(resource_name) do |f| %>
          <% if auth_info.present? %>
            <%= f.hidden_field :omniauth_provider %>
            <%= f.hidden_field :omniauth_uid %>
          <% end %>
          <%= render "shared/error_messages", target: resource %>
          <%= form_group(f, :login) do %>
            <%= f.text_field :login, class: "form-control form-control-lg", placeholder: t("users.login"), hint: t("users.suggest_using_twitter_id") %>
          <% end %>
          <%= form_group(f, :name) do %>
            <%= f.text_field :name, class: "form-control form-control-lg", placeholder: t("activerecord.attributes.user.name") %>
          <% end %>
          <%= form_group(f, :email) do %>
            <%= f.text_field :email, type: :email, class: "form-control form-control-lg", placeholder: t("activerecord.attributes.user.email") %>
          <% end %>
          <div class="form-group">
            <div class="custom-control custom-checkbox custom-checkbox-lg">
              <%= f.check_box :email_public, checked: true, class: "custom-control-input" %>
              <label for="user_email_public"  class="custom-form-label"><%= t("activerecord.attributes.user.email_public") %></label>
            </div>
          </div>
          <%= form_group(f, :password) do %>
            <%= f.password_field :password, class: "form-control form-control-lg", placeholder: t("activerecord.attributes.user.password") %>
          <% end %>
          <%= form_group(f, :password_confirmation) do %>
            <%= f.password_field :password_confirmation, class: "form-control form-control-lg", placeholder: t("activerecord.attributes.user.password_confirmation") %>
          <% end %>
          <%= form_group(f, :base, label: false) do %>
            <div class="input-group input-group-lg">
              <%= render "/shared/captcha_input" %>
            </div>
          <% end %>
          <div class="form-actions">
            <%= f.submit t('users.submit_new_user'), class: "btn btn-lg btn-primary", 'data-disable-with' => t("common.submitting") %>
          </div>
        <% end %>
      </div>
    </div>
  </div>
</div>
